import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-27
 * Time: 22:30
 */
public class Test {
}

class Solution {
    /**
     * 字符串中，第一个字符的唯一长度
     * @param s
     * @return
     */
    public static int firstUniqChar(String s) {
        int count[] = new int[26]; //计数数组，里面存放，字符出现的次数
        //遍历字符串，把对应字符下标开始计数
        for (int i = 0; i < s.length(); i++) {
            //根据长度，每次拿取字符
            char ch = s.charAt(i);
            count[ch - 'a']++;
        }
        //再遍历数组，找出第一个，并且只出现一次的字符
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (count[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的字符串");
        String ch = scanner.nextLine();
        System.out.println(firstUniqChar(ch));
    }

    public static void main2(String[] args) {
        String s = "afg";
        String str = new String("ertre");
        System.out.println(str.charAt(3));
        char ch = s.charAt(1);
        System.out.println(ch);

    }

    public static void main(String[] args) {
        String s1 = new String("bte");
        String s2 = new String("btE");

        String s3 = s1;
        System.out.println(s2 == s1);//false
        System.out.println(s3 == s1);//ture
        System.out.println(s1.equals(s3));//true


        //比较字符串，大小
        //根据对应字符，比较
        System.out.println(s1.compareTo(s2));

        String s5 = new String("bte");
        String s6 = new String("btefd");
        //对应字符，无法比较出来大小，就看长度

        System.out.println(s5.compareTo(s6));
        //忽略大小写
        System.out.println(s1.compareToIgnoreCase(s2));
    }
}
